1. A JSP is a servlet
  2. Elements
    1. scriptlets
      1. <% ... %>
      2. Java code can be here
      3. Code that will land in the "service method"
    2. directives
      1. Give instructions to the container at page translation time
      2. page directive
        1. import
          1. <%@ page import="foo.*" %>
          2. <%@ page import = "foo.*, java.util.*" %>
          3. multiple packages are separated by commas ","
        2. page properties
          1. Character Encoding
          2. Content type for the response
          3. Session object in the page
        3. attributes
          1. 13!
          2. Just four are covered in the exam :-)
          3. import
          4. java import
          5. isThreadSafe
          6. true
          7. Do Not implement
          8. SingleThreadModel
          9. I am Thread safe
          10. false
          11. Implement
          12. SingleThreadModel
          13. Bad idea
          14. contentType
          15. defines MIME
          16. isELIgnored
          17. Ignore EL when the page is translated
          18. isErrorPage
          19. Define a JSP error page
          20. default value
          21. false
          22. true
          23. Access to the exception object
          24. errorPage
          25. Defines URL to send uncaught Throwables
          26. if is a JSP
          27. isErrorPage = "true"
      3. taglib directive
        1. Defines tag libraries
      4. include directive
        1. Text and coded added to the page at translation time
          1. Headers
          2. Footers
          3. Navigation Bar
        2. Avoid code duplication
    3. expressions
      1. <%= .... %>
        1. <%= Counter.getCount() %>
          1. There is no need of semicolon here
        2. <% out.print(Counter.getCount()); %>
        3. the expression NEVER can be a method with a void return
          1. otherwise ERROR
        4. Arument of a "print()" methods
          1. No semicolons!
    4. declaration
      1. <%! ... %>
        1. <%! int count = 0; %>
        2. Declare members of the generated servlet class
          1. Variables
          2. can be static ones ;)
          3. Instance Variables
          4. Methods
        3. Declarations
  3. What really happens
    1. The translation
      1. The real Scenario in the Container
        1. 01. Looks at the directives, for information that might need during the translation
        2. 02. Creates a HttpServlet subclass
          1. Vendor specific
        3. 03. Check if there are packages to import
          1. Page directive with an import attribute
        4. 04. If there are declarations
          1. Write them after the class declaration and before the "service method"
        5. 05. Builds the service method
          1. _jspService()
          2. overriding the Servlet service() method
          3. The container declare and initialize the "Implicit Objects"
        6. 06. Combines HTML + scriptlets + expressions
          1. in the _jspService()
      2. Implicit Objects
        1. JspWritter
          1. Is not in the class hierarchy of:
          2. PrintWritter
          3. though
          4. It has the same methods
          5. adds some buffering capabilities
  4. The API of the generated Servlet
    1. jspInit()
      1. method called from the init() method
    2. jspDestroy()
      1. method called from the destroy() method
    3. _jspService()
      1. called by the service() method
      2. Diferent thread
      3. Container passes
        1. Request
        2. Response
  5. Lifecycle of a JSP
    1. Translate to java code
      1. Sintax Errors are caught here!
    2. Compile the code generated
      1. Java language syntax is caught here
    3. The container loads the newly generated servlet class
    4. The Container instantiates the servlet and runs the jspInit() method
      1. The object now is a servlet
    5. The container now creates a new thread to handle the client request and the _jspService() method runs
    6. Important note
      1. Translation and Compilation only happens once!
        1. On the first request
      2. It is also possible to translate/compilation in advance
        1. Vendor dependent
        2. Not guaranteed
        3. JSP procompilation protocol
          1. jsp_precompile
          2. The container then do
          3. Translation
          4. Compilation
  6. Initializing the JSP
    1. Configuring the INIT parameters in the DD
      1. <servlet> <servlet-name>...</servlet-name> <jsp-file>/TestInit.jsp</jsp-file> <init-param> <param-name /> <param-value ?> </init-param> </servlet>
        1. <jsp-file />
    2. Overriding jspInit()
      1. ServletConfig
      2. ServletContext
      3. Available to the Servlet, because the init() method has already run.
  7. Attributes in JSP
    1. Servlet
      1. Application
        1. getServletContext().setAttribute("key", Object);
      2. Request
        1. request.setAttribute("key", Object)
      3. Session
        1. request.getSession().setAttribute("key", Object);
      4. Page
        1. NO
    2. JSP
      1. Application
        1. application.setAttribute("key", Object)
      2. Request
        1. request.setAttribute("key", Object)
      3. Session
        1. session.setAttribute("key", Object)
      4. Page
        1. pageContext.setAttribute("key", Object)
    3. Page Context
      1. It is possible to get attributes from any scope
      2. Page Context
        1. getAttribute(String name, int scope )
          1. scope
          2. APPLICATION_SCOPE
          3. PAGE_SCOPE
          4. REQUEST_SCOPE
          5. SESSION_SCOPE
        2. setAttribute(String name, Object object, int scope)
        3. getAttribute(String name)
          1. Page Scope
        4. getAttributeNamesInScope(int scope)
        5. findAttribute(String name)
          1. Search for the attribute in all the four scopes
          2. Page
          3. Request
          4. Sesion
          5. Application
        6. same in Servlets
          1. getServletConfig()
          2. getServletContext()
        7. getRequest()
        8. getSession()
  8. Expression Language EL
    1. Expressions looks like this:
      1. ${something}
      2. ${applicationScope.mail}
        1. <%= application.getAttribute("mail") %>
    2. Ingnoring EL in the Container
      1. First of all
        1. EL is enabled by default!
      2. ingnoring it
        1. DD
          1. <el-ignored> true </el-ignored>
          2. <jsp-config> <jsp-property-group> <url-pattern>*.jsp</url-pattern> <el-ignored> true </el-ignored> </jsp-property-group> </jsp-config>
        2. Page Directive
          1. <%@ page isELIgnored = "true" %>
  9. Invalidate Scripting Elements in a JSP
    1. what
      1. scriptlets
      2. Java expressions
      3. declarations
    2. how
      1. <scripting-invalid> true </scripting-invalid>
        1. <jsp-config> <jsp-property-group> <url-pattern>*.jsp</url-pattern> <scripting-invalid>true</scripting-invalid> </jsp-property-group> </jsp-config>
  10. Actions
    1. Standard
      1. <jsp:include page="myFooter.jsp" />
    2. Other
      1. <c:set var="rate" value="32" />
  11. Notes:
    1. Template Text is just
      1. TEXT!!! in middle of HTML or JSP tags
    2. Another implicit variable is
      1. exception